//
//  JSMFeedBackViewController.m
//  TakeYouTourTogether
//
//  Created by dllo on 15/12/2.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMFeedBackViewController.h"

@interface JSMFeedBackViewController ()<MFMailComposeViewControllerDelegate>
@property(nonatomic, strong)BaseTextView *textView;
@property(nonatomic, strong)BaseButton *button;
@end

@implementation JSMFeedBackViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = LanguageTool(@"意见反馈");
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"<<" style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    [self createView];
}
#pragma mark - createView
- (void)createView{
    self.textView = [[BaseTextView alloc]init];
    [self.view addSubview:self.textView];
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(15);
        make.top.equalTo(self.view).with.offset(15);
        make.right.equalTo(self.view).with.offset(-15);
        make.height.mas_equalTo(250 * ALL_EDITION_HEIGHT);
    }];
    self.textView.font = [UIFont systemFontOfSize:16];
    self.textView.layer.borderWidth = 1;
    self.textView.layer.cornerRadius = 10;
    
    self.button = [BaseButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:self.button];
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).with.offset(-15);
        make.top.equalTo(self.textView.mas_bottom).with.offset(5);
        make.width.mas_equalTo(100 * ALL_EDITION_WIDTH);
        make.height.mas_equalTo(40 * ALL_EDITION_HEIGHT);
    }];
    [self.button setTitle:LanguageTool(@"发送") forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(sendButton) forControlEvents:UIControlEventTouchUpInside];
    
}
//发送
- (void)sendButton{
    [FeedBackTool sendFeedbackMail:self.textView.text delegate:self viewcontroller:self];
    [self.textView resignFirstResponder];
}
#pragma mark 点击空白处
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    [self.textView resignFirstResponder];
}

#pragma mark 协议方法
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
    NSString *message;
    switch (result) {
        case MFMailComposeResultCancelled:
            message = @"取消发送";
            break;
        case MFMailComposeResultSaved:
            message = @"保存草稿";
            break;
        case MFMailComposeResultFailed:
            message = @"发送失败";
            break;
        case MFMailComposeResultSent:
            message = @"已发送";
            break;
    }
    NSLog(@"%@", message);
    [self dismissViewControllerAnimated:YES completion:^{
    }];
    
}
#pragma mark 返回
- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
